import time

import requests
from lxml import etree

page = 1
while True:
    url = f"https://www.bjcourt.gov.cn/zxxx/indexOld.htm?st=1&zxxxlx=100013007&bzxrlx=&bzxrxm=&zrr=&frhqtzz=&jbfyId=&ah=&dqxh=26&page={page}"
    headers = {
        "cookie":"vh2PJqrvyx=MDAwM2IyYWYxZTQwMDAwMDAwMDQwcy5eK1AxNzQ0MTM0ODcy; 6JDgKK8lEy=MDAwM2IyYWYxZTQwMDAwMDAwMDMwNBQeWB4xNzQ0MTM0ODcy; thguid-r=1745143098452733952; JSESSIONID=node01uzixwpx37rlb10r5d6r1xzzsr13227011.node0; __jsluid_s=a4167b7a2335f6d241eedb3b1357fc45",
        "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
    }
    response = requests.get(url,headers=headers)
    tree = etree.HTML(response.text)
    rows = tree.xpath('//table[@class="table_list_02"]/tr')
    for row in rows[1:]:
        cells = row.xpath('.//td | .//th')
        row_data = [cell.text.strip() if cell.text else '' for cell in cells]
        print(f"序号：{row_data[0]}，姓名/名称：{row_data[1]}，证件类型：{row_data[2]}，证件号码/组织机构代码：{row_data[3]}，执行案号：{row_data[4]}，执行法院，立案时间：{row_data[5]}")
        time.sleep(0.1)
    page+=1

